package com.enjoyor.soa.traffic.rest.efoms.common;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.enjoyor.soa.traffic.api.ubms.dto.TrafficDicDto;
import com.enjoyor.soa.traffic.api.ubms.dto.VehicleDicDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.invoke.DubboUbmsServiceInvoke;
import com.enjoyor.soa.traffic.rest.efoms.helper.CheckPojoHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class SynDeviceStatusListener implements CommandLineRunner {
    
	@Autowired
	private DubboUbmsServiceInvoke serviceInvoke;
	
    @Override
    public void run(String... args) throws Exception {
    	getGlobal();
    }
    
    /*全局变量封装；*/
    private void getGlobal(){

        // TODO Auto-generated method stub
        try {
        	/*方向字典名称获取；*/
        	ResultPojo resultPojoDir = serviceInvoke.getTrafficInfo("ROADDIRECT");
        	if(CheckPojoHelper.isValid(resultPojoDir)){
        		List<TrafficDicDto> listTrafficDicDto = (List<TrafficDicDto>) resultPojoDir.getResultList();
        		for(int i = 0;i<listTrafficDicDto.size();i++){
        			Global.DicTraffic.put(listTrafficDicDto.get(i).getDicCode(), listTrafficDicDto.get(i).getDicName());
        		}
        	}
        	/*车牌类型字典名称获取；*/
        	ResultPojo resultPojoLicType = serviceInvoke.getVehicleInfo("VEHPLATETYPE");
        	if(CheckPojoHelper.isValid(resultPojoLicType)){
        		List<VehicleDicDto> listVehicleDicDto = (List<VehicleDicDto>) resultPojoLicType.getResultList();
        		for(int i = 0;i<listVehicleDicDto.size();i++){
        			Global.DicTraffic.put(listVehicleDicDto.get(i).getDicCode(), listVehicleDicDto.get(i).getDicName());
        		}
        	}
        	/*车牌颜色字典名称获取*/
        	ResultPojo resultPojoLicColor = serviceInvoke.getVehicleInfo("PLATECOLOR");
        	if(CheckPojoHelper.isValid(resultPojoLicColor)){
        		List<VehicleDicDto> listVehicleDicDto = (List<VehicleDicDto>) resultPojoLicColor.getResultList();
        		for(int i = 0;i<listVehicleDicDto.size();i++){
        			Global.DicTraffic.put(listVehicleDicDto.get(i).getDicCode(), listVehicleDicDto.get(i).getDicName());
        		}
        	}
        	
        	/*车身颜色字典名称获取；*/
        	ResultPojo resultPojoCarColor = serviceInvoke.getVehicleInfo("VEHCOLOR");
        	if(CheckPojoHelper.isValid(resultPojoCarColor)){
        		List<VehicleDicDto> listVehicleDicDto = (List<VehicleDicDto>) resultPojoCarColor.getResultList();
        		for(int i = 0;i<listVehicleDicDto.size();i++){
        			Global.DicTraffic.put(listVehicleDicDto.get(i).getDicCode(), listVehicleDicDto.get(i).getDicName());
        		}
        	}
    
        } catch (Exception e) {
            // throw e;
            return;
        }
    
    }
}
